package io.renren.auth.controller;


import io.renren.auth.service.SysLoginService;
import io.renren.auth.utils.JwtUtils;
import io.renren.common.form.SysLoginForm;
import io.renren.common.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
public class LoginController {

    @Autowired
    private SysLoginService sysLoginService;

    @Autowired
    private JwtUtils jwtUtils;

    @GetMapping("test")
    public R test(){
        return R.ok();
    }



    @PostMapping("login")
    public R login(@RequestBody SysLoginForm form){

        //用户登录
        Map<String, Object> r =  sysLoginService.login(form);

        //生成token
        //String token = jwtUtils.generateToken(1);

        Map<String, Object> map = new HashMap<>();
        map.put("token", r.get("token"));
        map.put("expire", r.get("expire"));

        return R.ok(map);
    }

}
